package com.example.test.chapter15;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.example.test.R;
import com.example.test.app.main.ApplicationMain;

public class MainChapter15 extends Activity implements OnItemClickListener {
	private String[] sample = new String[] { "onSaveInstanceState",
			"onRetainNonConfigurationInstance", "onConfiguratuionChanged" };
	private int[] _id = new int[] { 1, 2, 3 };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainchapter15);
		ListView listView = (ListView) findViewById(R.id.listViewChapter15);
		listView.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, sample));
		listView.setOnItemClickListener(this);
		Button btn = (Button) findViewById(R.id.backpage);
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getApplicationContext(),
						ApplicationMain.class);
				startActivity(intent);
				finish();
			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		switch (_id[arg2]) {
		case 1:
			startActivity(new Intent(this, RotationA.class));
			break;
		case 2:
			startActivity(new Intent(this, RotationTwoDemo.class));
			break;
		case 3:
			startActivity(new Intent(this, RotationThreeDemo.class));
		default:
			break;
		}
	}
}
